package groupb6.shopsystem.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import groupb6.shopsystem.pojo.entity.Example;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/*
 *
 * Swagger是一种基于注解自动生成api文档的组件。其会自动扫描Controller目录中的controller类，并在服务启动后渲染一个API文档的静态页面。
 * 通过访问对应网址即可查看api文档。
 *
 * 访问方式：http://ip:port/doc.html#
 * ip：启动后端服务的ip地址，本地启动为localhost，远程服务器部署待定
 * port：application.properties中可查看启动端口，本程序为9900
 *基于注解：通过@Apixxx 注解的方式完成对接口和表单/响应的描述。大家可以本地启动程序，访问以上地址查看api文档启动效果
 *
 *@zhangyn
 * */
@Api(tags = "00:swagger案例")
@ApiSupport(author = "zhangyn")
@Controller
@RequestMapping("/example")
public class ExampleController {

    @ApiImplicitParam(name = "name", value = "传入参数姓名", required = true)
    @ApiOperation(value = "接口描述1", code = 1000)
    @PostMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
        return "Hello " + name;
    }

    @ApiOperationSupport(author = "这里写接口负责人")
    @ApiOperation(value = "接口描述2", code = 1000)
    @ApiResponses(value = {
            @ApiResponse(code = 1000, message = "seccess", response = Example.class),
            @ApiResponse(code = 1001, message = "参数有误", response = Example.class)
    })
    @GetMapping("/get")
    @ResponseBody
    public Example getExample(@RequestBody Example example) {
        return example;
    }


}
